from .models import myUser
from rest_framework import serializers


class CustomUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = myUser
        fields = ["id", "username", "password", "email", "idcard", "company", "department", "workshop", "position", "is_see", "is_edit", "is_delete", "is_auditor", "is_area", "area", "role", "base"]


class RegisterSerializer(serializers.ModelSerializer):
    class Meta:
        model = myUser
        fields = ["username", "password", "email", "idcard", "company", "department", "workshop", "position", "area", "role", "base"]
        extra_kwargs = {"password": {"write_only": True}}

    def create(self, validated_data):
        user = myUser.objects.create_user(**validated_data)
        return user
